layui.use(["table", "form"], function () {
    let table = layui.table;
    table.render({
        elem: '#blacklist',
        title: '我的屏蔽',
        url: '/hire/employer/blacklist/data',
        response: {
            statusName: 'code',
            statusCode: 200,
            msgName: 'msg',
            dataName: 'data'
        },
        // data: [{"id":2,"employeeId":1,"employerId":2,"employeeName":"李文轩"},{"id":2,"employeeId":2,"employerId":2,"employeeName":"李溢"},{"id":2,"employeeId":3,"employerId":2,"employeeName":"王晨"},{"id":2,"employeeId":9,"employerId":2,"employeeName":"林美地"}],
        height: "300px",
        cols: [[
            {type: 'checkbox', fixed: 'left'},
            {field: 'num', title: '序号', sort: true, align: 'center'},
            {field: 'employeeId', title: '求职者id', align: 'center'},
            {field: 'employeeName', title: '求职者姓名', align: 'center'},
            {field: 'relationName', toolbar: '#barDemo', title: '操作', align: 'center'}
        ]],
        text: {none: '您没有屏蔽的用户'}
    });
    table.on('tool(blacklist)', function (obj) {
        if (obj.event == 'cancel') {
            layer.confirm('请确认是否取消屏蔽', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                // 获取当前选中的id - obj.data.id
                let id = obj.data.id;
                let param = {id: id};
                $.post('/hire/employer/del/blacklist', param, function (res) {
                    if (res.code == '200') {
                        // 删除成功则跳转页面
                        layer.msg('取消屏蔽成功', {icon: 1});
                        obj.del();
                        // table.reload('blacklist', {
                        //     url: '/hire/employer/blacklist/data'
                        // })
                    }
                });

            });

        }
    });
});

$(function () {
    let ws;
    // 首先检测浏览器是否支持websocket
    console.log("正在运行");
    if("WebSocket" in window) {
        console.log("您的浏览器支持websocket");
        // $("#content").html("您的浏览器支持websocket");

        // 获取招聘者id
        let clientID = $("#eid").val();

        // 创建WebSocket对象,需要注意请求路径
        ws = new WebSocket("ws://127.0.0.1:8081/hire/web/" + clientID);

        // 与服务端建立连接时触发
        ws.onopen = function () {
            // 模拟发送数据到服务器
            ws.send("您好服务端,我是客户端:"+clientID);
        };

        // 接收到服务端消息时触发
        ws.onmessage = function (evt) {
            let received_msg = evt.data;
           layer.msg(received_msg,{
               offset: '50px'
           });
        };

        // 服务端关闭连接时出发
        ws.onclose = function () {
            console.error("连接已关闭")
        }
    }
});